package edu.ncsu.csc.ip.client;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import edu.ncsu.csc.ip.server.ClientBean;

/**
 * Contains the list of active clients.
 * 
 * 
 * 
 * @author Moin Ayazifar <mayazif@ncsu.edu>
 * @author Steven Elliott <sdelliot@ncsu.edu>
 * 
 */

public class ActiveClientIndex {

	public final static Integer TTL_UPDATE_INTERVAL = 60;

	private Map<Integer, ClientBean> clientIndexMap = new ConcurrentHashMap<Integer, ClientBean>();

	protected ActiveClientIndex() {
		// Exists only to defeat instantiation.
	}

	public void addClients(List<ClientBean> clientBeanList) {
		clientIndexMap.clear();
		if (clientBeanList != null)
			for (ClientBean clientBean : clientBeanList)
				clientIndexMap.put(clientBean.getCookie(), clientBean);
	}

	public List<ClientBean> getClients() {
		List<ClientBean> activeClients = new ArrayList<ClientBean>();
		for (ClientBean clientBean : clientIndexMap.values())
			activeClients.add(clientBean);
		return activeClients;
	}

}
